package com.ctim.dao.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
@PropertySource("classpath:db-${spring.profiles.active}.properties")
public class DataBaseConfiguration {
	
	@Bean(name="readDataSource")
	@ConfigurationProperties("spring.datasource.druid.read")
	public DataSource readDataSource() {
		return DruidDataSourceBuilder.create().build();
	}

	@Primary
	@Bean(name="writeDataSource")
	@ConfigurationProperties("spring.datasource.druid.write")
	public DataSource writeDataSource() {
		return DruidDataSourceBuilder.create().build();
	}

}